package com.tinem.platform.web.notice;

import com.tinem.platform.module.starter.web.filter.CorsFilter;
import com.tinem.platform.web.notice.filter.NoticeFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.client.RestTemplate;

/**
 * @author fengzhihao
 * @version v1
 * @program: platform
 * @className WebLinkApplication
 * @description TODO
 * @site 
 * @company 
 * @create 2020-07-08 19:48
 */
@Slf4j
@SpringBootApplication
@EnableDiscoveryClient
public class NoticeWebApplication {

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();

        SpringApplication.run(NoticeWebApplication.class, args);

        long endTime = System.currentTimeMillis();
        System.out.println("start success; duration:("+ (endTime - startTime) +");startTime:("+startTime+");endTime:("+ endTime +")");
        log.info("start success; duration:({});startTime:({});endTime:({})",(endTime - startTime),startTime,endTime);

    }

    @Bean
    public FilterRegistrationBean corsFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setFilter(new CorsFilter());
        filterRegistrationBean.setName("corsFilter");
        filterRegistrationBean.addUrlPatterns("*.do","*.api","*.notify","*");
        return filterRegistrationBean;
    }
    @Bean
    public FilterRegistrationBean noticeFilter(RestTemplate restTemplate, StringRedisTemplate stringRedisTemplate) {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setFilter(new NoticeFilter(restTemplate,stringRedisTemplate));
        filterRegistrationBean.setName("noticeFilter");
        filterRegistrationBean.addUrlPatterns("*.notify");
        return filterRegistrationBean;
    }
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
